<%--
  Created by IntelliJ IDEA.
  User: ykj
  Date: 16/3/2
  Time: 下午8:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>理财产品-产品详细</title>
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/financial.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/purchase.css">
    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="${pageContext.request.contextPath}/easyui/jquery.min.js"></script>

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/bootstrap/js/jquery.bootstrap.min.js"></script>

    <script>
        $(document).ready(function(){
            $('.redeemBtn').click(function(){
                var purchasesId = $(this).attr('purchasesId');
                $.ajax({
                    url: "../purchases/redeem",
                    type: "POST",
                    data: {id:purchasesId},
                    error: function () {
                        $.messager.alert("网络超时，请稍后再试");
                    },
                    success: function (result) {
                        $.messager.alert('赎回成功,获得总收益:'+result.earning);
//                        window.location = '../purchases/detail';
                    }
                });
            });

        });
    </script>
</head>
<body>
    <jsp:include page="topbar.jsp" flush="true"/>
    <div class="container workbench">
        <table class="table table-striped purchase-table">
            <thead>
            <tr>
                <th>#</th>
                <th>产品</th>
                <th>年化收益率</th>
                <th>投资金额(元)</th>
                <th>起息时间</th>
                <th>到期时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
                <c:forEach var="purchase" items="${purchases.list}" varStatus="status">
                    <tr>
                        <th scope="row">${status.count}</th>
                        <td><a href="../product/detail?id=${purchase.productId}" class="product-link">${purchase.productName}</a></td>
                        <td>${purchase.rateReturn}%</td>
                        <td>${purchase.invest}元</td>
                        <td><fmt:formatDate value="${purchase.createTime}" pattern="yyyy-MM-dd"/></td>
                        <td><fmt:formatDate value="${purchase.expireDate}" pattern="yyyy-MM-dd"/></td>
                        <td><button purchasesId="${purchase.id}" class="btn btn-danger redeemBtn">赎回</button></td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>
        <div class="text-center">
            <ul class="pagination">
                <li><a href="#">&laquo;</a></li>
                <c:forEach begin="1" end="${purchases.totalPage}" varStatus="status">
                    <li><a href="?page=${status.index}">${status.index}</a></li>
                </c:forEach>
                <li><a href="#">&raquo;</a></li>
            </ul>
        </div>
    </div>
</body>
</html>
